package cn.datawin.common.state.template;

import org.squirrelframework.foundation.fsm.UntypedAnonymousAction;
import org.squirrelframework.foundation.fsm.UntypedStateMachineBuilder;

import java.util.ArrayList;
import java.util.List;

/**
 * 状态机模板基础类
 * @Author: huanyayun
 * @Date: 2021/10/27 15:56
 */
public abstract class BaseTemplate {

    /**
     * 外部状态名称
     */
    protected String stateName;

    /**
     * 进入外部状态stateName需要执行的actions
     */
    protected List<UntypedAnonymousAction> actions;

    /**
     * 进入外部状态stateName需要执行的方法名
     */
    protected String entryFunc;

    /**
     * 离开外部状态stateName需要执行的方法名
     */
    protected String exitFunc;

    /**
     * 执行actions的流程，根据不同模板的情况，自己实现
     * @param builder
     */
    public abstract void execActions(UntypedStateMachineBuilder builder);

    public BaseTemplate(String stateName, List<UntypedAnonymousAction> actions, String entryFunc, String exitFunc) {
        this.stateName = stateName;
        this.actions = actions;
        this.entryFunc = entryFunc;
        this.exitFunc = exitFunc;
    }


    public BaseTemplate(String stateName, UntypedAnonymousAction action, String entryFunc, String exitFunc) {
        this.stateName = stateName;
        this.actions = new ArrayList<>();
        this.actions.add(action);
        this.entryFunc = entryFunc;
        this.exitFunc = exitFunc;
    }

    public String getStateName(){
        return  stateName;
    }
}
